/**
 * @author scylla
 * @version V1.0
 * @Project echo-java-base
 * @Title 内部类1  继承Thread
 * @Description *
 * @Package concurrent.mthread.self
 * @Since 2021/7/29 1:12 下午
 */
package concurrent.mthread.self;

public class InnerThread1 {

    private int countDown = 5;
    private Inner inner;

    public InnerThread1(String name) {
        this.inner = new Inner(name);
    }

    private class Inner extends Thread {

        /**
         * 构造名称后直接启动
         *
         * @param name 线程名称
         */
        Inner(String name) {
            super(name);
            start();
        }

        @Override
        public String toString() {
            return getName() + ": " + countDown;
        }

        @Override
        public void run() {
            try {
                for (; ; ) {
                    System.out.println(this);
                    if (--countDown == 0) return;
                    sleep(10);
                }
            } catch (Exception e) {
                System.err.println(e.getMessage());
            }
        }
    }
}
